package cn.fl.fgi.service.impl;

import cmm.mid.core.framework.page.Pager;
import cn.cmm.base.framework.utils.CollectionUtils;
import cn.cmm.base.framework.utils.StringUtils;
import cn.fl.fgi.api.IFgiFunCfgApiService;
import cn.fl.fgi.api.condition.FgiFunCfgQueryCondition;
import cn.fl.fgi.api.dto.FgiFunCfgDTO;
import cn.fl.fgi.api.dto.FgiUpDetailDTO;
import cn.fl.fgi.service.IFgiFunCfgService;
import cn.fl.fgi.transform.FgiFunCfgVOTransform;
import cn.fl.fgi.vo.FgiFunCfgVO;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class FgiFunCfgServiceImpl implements IFgiFunCfgService {
    @Autowired
    private IFgiFunCfgApiService fgiFunCfgApiService ;
    @Override
    public Pager searchListPage(FgiFunCfgQueryCondition condition, Integer pageNum, Integer pageSize) {
        Pager page = new Pager();
        String s = fgiFunCfgApiService.searchListPage(condition,pageNum,pageSize);
        Integer total = 1 ;
        List<FgiFunCfgDTO> dtoList = null ;
        if(StringUtils.isNotEmpty(s)){
            JSONObject obj = JSONObject.parseObject(s);
            Object o = obj.get("total");
            if(o != null ){
                total = Integer.valueOf(o.toString());
            }
            page.setTotalCount(total);
            Object data = obj.get("dataList");
            if(data != null){
                dtoList = JSON.parseArray(data.toString(), FgiFunCfgDTO.class);
                if(CollectionUtils.isNotEmpty(dtoList)){
                    page.setResultList(FgiFunCfgVOTransform.toVOList(dtoList));
                }
            }
        }
        return page;
    }

    @Override
    public boolean addFgiFunCfg(FgiFunCfgVO fgiFunCfgVO) {
        boolean b = fgiFunCfgApiService.addFgiFunCfg(FgiFunCfgVOTransform.toDTO(fgiFunCfgVO));
        return b;
    }
}
